/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Space3DPanelView.java
 *
 * Created on 31/05/2011, 00:07:46
 */
package view;

import java.awt.BorderLayout;
import java.awt.Canvas;
import monkey.Space3DMonkey;
import util.Monkey4Canvas;

/**
 *
 * @author mathyas
 */
public class Space3DPanelView extends BasePanelControl {

    private Space3DMonkey monkey;

    /** Creates new form Space3DPanelView */
    public Space3DPanelView() {
        initComponents();
        monkey = new Space3DMonkey();
        Canvas canvas = Monkey4Canvas.parse(monkey);
        jPanelMonkey.setLayout(new BorderLayout());
        jPanelMonkey.add(canvas);
        monkey.startCanvas();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jPopupMenuOpcoes = new javax.swing.JPopupMenu();
        jMenuEixos = new javax.swing.JMenu();
        jRadioButtonMenuItemEixoX = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItemEixoY = new javax.swing.JRadioButtonMenuItem();
        jRadioButtonMenuItemEixoZ = new javax.swing.JRadioButtonMenuItem();
        jLabelEspaco3d = new javax.swing.JLabel();
        jLabelPontoEscolha = new javax.swing.JLabel();
        jLabelPontoX = new javax.swing.JLabel();
        jLabelPontoY = new javax.swing.JLabel();
        jLabelPontoZ = new javax.swing.JLabel();
        jTextFieldPontoX = new javax.swing.JTextField();
        jTextFieldPontoY = new javax.swing.JTextField();
        jTextFieldPontoZ = new javax.swing.JTextField();
        jButtonMostrar = new javax.swing.JButton();
        jButtonReset = new javax.swing.JButton();
        jCheckBoxEixoX = new javax.swing.JCheckBox();
        jCheckBoxEixoY = new javax.swing.JCheckBox();
        jCheckBoxEixoZ = new javax.swing.JCheckBox();
        jPanelMonkey = new javax.swing.JPanel();
        jCheckBoxPlanoXY = new javax.swing.JCheckBox();
        jCheckBoxPlanoXZ = new javax.swing.JCheckBox();
        jCheckBoxPlanoYZ = new javax.swing.JCheckBox();

        jMenuEixos.setText("jMenu1");

        jRadioButtonMenuItemEixoX.setSelected(true);
        jRadioButtonMenuItemEixoX.setText("jRadioButtonMenuItem1");
        jRadioButtonMenuItemEixoX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItemEixoXActionPerformed(evt);
            }
        });
        jMenuEixos.add(jRadioButtonMenuItemEixoX);

        jRadioButtonMenuItemEixoY.setSelected(true);
        jRadioButtonMenuItemEixoY.setText("jRadioButtonMenuItem1");
        jRadioButtonMenuItemEixoY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItemEixoYActionPerformed(evt);
            }
        });
        jMenuEixos.add(jRadioButtonMenuItemEixoY);

        jRadioButtonMenuItemEixoZ.setSelected(true);
        jRadioButtonMenuItemEixoZ.setText("jRadioButtonMenuItem1");
        jRadioButtonMenuItemEixoZ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jRadioButtonMenuItemEixoZActionPerformed(evt);
            }
        });
        jMenuEixos.add(jRadioButtonMenuItemEixoZ);

        jPopupMenuOpcoes.add(jMenuEixos);

        jLabelEspaco3d.setFont(new java.awt.Font("Tahoma", 0, 14));
        jLabelEspaco3d.setText("Espaço 3-D");

        jLabelPontoEscolha.setText("Escolha as coordenadas:");

        jLabelPontoX.setText("Ponto X:");

        jLabelPontoY.setText("Ponto Y:");

        jLabelPontoZ.setText("Ponto Z:");

        jTextFieldPontoX.setText("0");

        jTextFieldPontoY.setText("0");

        jTextFieldPontoZ.setText("0");

        jButtonMostrar.setText("Mover");
        jButtonMostrar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonMostrarActionPerformed(evt);
            }
        });

        jButtonReset.setText("Restaurar");
        jButtonReset.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButtonResetActionPerformed(evt);
            }
        });

        jCheckBoxEixoX.setSelected(true);
        jCheckBoxEixoX.setText("Eixo X");
        jCheckBoxEixoX.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxEixoXActionPerformed(evt);
            }
        });

        jCheckBoxEixoY.setSelected(true);
        jCheckBoxEixoY.setText("Eixo Y");
        jCheckBoxEixoY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxEixoYActionPerformed(evt);
            }
        });

        jCheckBoxEixoZ.setSelected(true);
        jCheckBoxEixoZ.setText("Eixo Z");
        jCheckBoxEixoZ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxEixoZActionPerformed(evt);
            }
        });

        jPanelMonkey.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jPanelMonkeyMouseClicked(evt);
            }
        });

        javax.swing.GroupLayout jPanelMonkeyLayout = new javax.swing.GroupLayout(jPanelMonkey);
        jPanelMonkey.setLayout(jPanelMonkeyLayout);
        jPanelMonkeyLayout.setHorizontalGroup(
            jPanelMonkeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 800, Short.MAX_VALUE)
        );
        jPanelMonkeyLayout.setVerticalGroup(
            jPanelMonkeyLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 600, Short.MAX_VALUE)
        );

        jCheckBoxPlanoXY.setText("Plano X-Y");
        jCheckBoxPlanoXY.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxPlanoXYActionPerformed(evt);
            }
        });

        jCheckBoxPlanoXZ.setText("Plano X-Z");
        jCheckBoxPlanoXZ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxPlanoXZActionPerformed(evt);
            }
        });

        jCheckBoxPlanoYZ.setText("Plano Y-Z");
        jCheckBoxPlanoYZ.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBoxPlanoYZActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(10, 10, 10)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jCheckBoxPlanoYZ)
                    .addComponent(jCheckBoxPlanoXY)
                    .addComponent(jCheckBoxPlanoXZ)
                    .addComponent(jCheckBoxEixoY, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxEixoZ, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBoxEixoX, javax.swing.GroupLayout.PREFERRED_SIZE, 136, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelPontoY)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jTextFieldPontoY, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jButtonReset, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addComponent(jButtonMostrar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabelPontoZ)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextFieldPontoZ, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jLabelPontoEscolha, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addComponent(jLabelPontoX)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jTextFieldPontoX, javax.swing.GroupLayout.PREFERRED_SIZE, 77, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jPanelMonkey, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            .addGroup(layout.createSequentialGroup()
                .addGap(41, 41, 41)
                .addComponent(jLabelEspaco3d, javax.swing.GroupLayout.PREFERRED_SIZE, 115, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(538, 538, 538))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabelEspaco3d)
                .addGap(18, 18, 18)
                .addComponent(jCheckBoxEixoX)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxEixoY)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxEixoZ)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxPlanoXY)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxPlanoXZ)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jCheckBoxPlanoYZ)
                .addGap(18, 18, 18)
                .addComponent(jLabelPontoEscolha)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldPontoX, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabelPontoX))
                .addGap(14, 14, 14)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPontoY)
                    .addComponent(jTextFieldPontoY, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(17, 17, 17)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabelPontoZ)
                    .addComponent(jTextFieldPontoZ, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(14, 14, 14)
                .addComponent(jButtonMostrar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButtonReset)
                .addContainerGap(201, Short.MAX_VALUE))
            .addComponent(jPanelMonkey, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jButtonMostrarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonMostrarActionPerformed
        float x = Float.parseFloat(jTextFieldPontoX.getText());
        float y = Float.parseFloat(jTextFieldPontoY.getText());
        float z = Float.parseFloat(jTextFieldPontoZ.getText());

        monkey.setBoxCoord(x, y, z);
    }//GEN-LAST:event_jButtonMostrarActionPerformed

    private void jCheckBoxEixoXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxEixoXActionPerformed
        monkey.exibirEixo('x', jCheckBoxEixoX.isSelected());
    }//GEN-LAST:event_jCheckBoxEixoXActionPerformed

    private void jCheckBoxEixoYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxEixoYActionPerformed
        monkey.exibirEixo('y', jCheckBoxEixoY.isSelected());
    }//GEN-LAST:event_jCheckBoxEixoYActionPerformed

    private void jCheckBoxEixoZActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxEixoZActionPerformed
        monkey.exibirEixo('z', jCheckBoxEixoZ.isSelected());
    }//GEN-LAST:event_jCheckBoxEixoZActionPerformed

    private void jButtonResetActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonResetActionPerformed
        monkey.setBoxCoord(0, 0, 0);
        monkey.exibirEixo('x', true);
        monkey.exibirEixo('y', true);
        monkey.exibirEixo('z', true);
        monkey.exibirPlanoXY(false);
        monkey.exibirPlanoXZ(false);
        monkey.exibirPlanoYZ(false);

        jTextFieldPontoX.setText("0");
        jTextFieldPontoY.setText("0");
        jTextFieldPontoZ.setText("0");
        jCheckBoxEixoX.setSelected(true);
        jCheckBoxEixoY.setSelected(true);
        jCheckBoxEixoZ.setSelected(true);
        jCheckBoxPlanoXY.setSelected(false);
        jCheckBoxPlanoXZ.setSelected(false);
        jCheckBoxPlanoYZ.setSelected(false);
    }//GEN-LAST:event_jButtonResetActionPerformed

    private void jCheckBoxPlanoXYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxPlanoXYActionPerformed
        monkey.exibirPlanoXY(jCheckBoxPlanoXY.isSelected());
    }//GEN-LAST:event_jCheckBoxPlanoXYActionPerformed

    private void jCheckBoxPlanoXZActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxPlanoXZActionPerformed
        monkey.exibirPlanoXZ(jCheckBoxPlanoXZ.isSelected());
    }//GEN-LAST:event_jCheckBoxPlanoXZActionPerformed

    private void jCheckBoxPlanoYZActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBoxPlanoYZActionPerformed
        monkey.exibirPlanoYZ(jCheckBoxPlanoYZ.isSelected());
    }//GEN-LAST:event_jCheckBoxPlanoYZActionPerformed

    private void jPanelMonkeyMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jPanelMonkeyMouseClicked
        if(evt.isPopupTrigger()) {
            
        }
    }//GEN-LAST:event_jPanelMonkeyMouseClicked

    private void jRadioButtonMenuItemEixoXActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItemEixoXActionPerformed
        jCheckBoxEixoXActionPerformed(evt);
    }//GEN-LAST:event_jRadioButtonMenuItemEixoXActionPerformed

    private void jRadioButtonMenuItemEixoYActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItemEixoYActionPerformed
        jCheckBoxEixoYActionPerformed(evt);
    }//GEN-LAST:event_jRadioButtonMenuItemEixoYActionPerformed

    private void jRadioButtonMenuItemEixoZActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jRadioButtonMenuItemEixoZActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_jRadioButtonMenuItemEixoZActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButtonMostrar;
    private javax.swing.JButton jButtonReset;
    private javax.swing.JCheckBox jCheckBoxEixoX;
    private javax.swing.JCheckBox jCheckBoxEixoY;
    private javax.swing.JCheckBox jCheckBoxEixoZ;
    private javax.swing.JCheckBox jCheckBoxPlanoXY;
    private javax.swing.JCheckBox jCheckBoxPlanoXZ;
    private javax.swing.JCheckBox jCheckBoxPlanoYZ;
    private javax.swing.JLabel jLabelEspaco3d;
    private javax.swing.JLabel jLabelPontoEscolha;
    private javax.swing.JLabel jLabelPontoX;
    private javax.swing.JLabel jLabelPontoY;
    private javax.swing.JLabel jLabelPontoZ;
    private javax.swing.JMenu jMenuEixos;
    private javax.swing.JPanel jPanelMonkey;
    private javax.swing.JPopupMenu jPopupMenuOpcoes;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItemEixoX;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItemEixoY;
    private javax.swing.JRadioButtonMenuItem jRadioButtonMenuItemEixoZ;
    private javax.swing.JTextField jTextFieldPontoX;
    private javax.swing.JTextField jTextFieldPontoY;
    private javax.swing.JTextField jTextFieldPontoZ;
    // End of variables declaration//GEN-END:variables

    public void destroy() {
        monkey.stop(true);
    }

    @Override
    public void start() {
        monkey.setPauseOnLostFocus(false);
        
    }

    @Override
    public void pause() {
        monkey.setPauseOnLostFocus(true); //para não pausar quando perder o foco
    }
    
    
}
